// pages/index/index.js
const app = getApp()
const api = require("../../style/api.js")
const sData = require("../utils/testData.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rightLeftKey: app.globalData.nowKey,
    upDownKey: 0,
    finish: true,
    nowKey: app.globalData.nowKey,
    nowStepKey: app.globalData.nowStep,
    windowHeight: undefined,
    statusBar: undefined,
    process: sData.process,
    step: sData.step,
    nowProcess: 0,
    waitMain: 0,
    mainPngSrc: "cloud://partybuilding-ap3rs.7061-partybuilding-ap3rs-1301916504/mainStepPic/",
    gender: '1'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    app.Login(function(token){
      console.log(token)
      api.request.get("https://hua-bang.club/Party/public/index.php/client/v1/user/stage",{}, {Authorization:token}).then(e=>{
        console.log(e)
      })
      api.request.get("https://hua-bang.club/Party/public/index.php/client/v1/user/task",{}, {Authorization:token}).then(e=>{
        console.log(e)
      })
    })
    const that = this
    let sysInfo = wx.getSystemInfoSync()
    let mbb = wx.getMenuButtonBoundingClientRect()
    that.setData({
      topText: mbb.top,
      topTextSize: mbb.height
    })
    that.setData({
      windowHeight: sysInfo.windowHeight
    })
  },
  toNowStep(e) {
    let R = String.fromCharCode(this.data.nowKey + 65)
    let S = String.fromCharCode(this.data.nowStepKey + 96)
    wx.navigateTo({
      url: '/package' + R + '/pages/' + S + '/index',
    })
  },
  downToStep(e) {
    console.log(e)
    let R = String.fromCharCode(e.currentTarget.dataset.r + 65)
    let S = String.fromCharCode(e.currentTarget.dataset.s + 97)
    wx.navigateTo({
      url: '/package' + R + '/pages/' + S + '/index',
    })
  },
  toBeforeStep(e) {
    wx.navigateTo({
      url: '/pages/beforeStep/index',
    })
  },
  toNextStep(e) {
    wx.navigateTo({
      url: '/pages/nextStep/index',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.setData({
      nowKey: app.globalData.nowKey,
      nowStepKey: app.globalData.nowStep
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  changeRightLeft(e) {
    const that = this
    that.setData({
      rightLeftKey: e.detail.current
    })
  },
  changeUpDown(e) {
    const that = this
    that.setData({
      upDownKey: e.detail.current
    })
  }
})